<template>
	<!-- 首页 -->
	<view>
		<image class="homeTopBg" src="/static/tabbar/homeTopBg.png" mode=""></image>
		<view class="head">
			<view class="accumulate">平台累计鉴定</view>
			<view class="accumulate_num">{{count}}次</view>
			<view class="apply_btn" @click="$fn.jumpPage('/pages/home/pages/appraisalApply')">提交鉴定申请</view>
		</view>

		<view class="search" @click="$fn.jumpPage('/pages/home/pages/search')">
			<u-search style="pointer-events: none;" placeholder="输入鉴定编号" height="80rpx" :showAction="false" disabled
				inputAlign="center" v-model="keyword"></u-search>
		</view>

		<view class="banner">
			<u-swiper :list="bannerList" previousMargin="30" nextMargin="30" circular radius="5"
				@click="clickBanner" bgColor="#ffffff"></u-swiper>
		</view>

		<view class="divider"></view>

		<view class="tabs">
			<view class="tab" :class="{tab_a:selectTab==1}" @click="changeTab(1)">球鞋鉴定</view>
			<view class="tab" :class="{tab_a:selectTab==2}" @click="changeTab(2)">奢潮鉴定</view>
			<view class="taball" :class="{tab_a:selectTab==3}" @click="changeTab(3)">
				所有
				<u-icon name="arrow-down" color="#666666" size="30rpx"></u-icon>
			</view>
		</view>

		<c-scroll-list ref="list" :api="api" :option="{height:800}" :apiParams="from" @load="load">
			<view class="list">
				<view class="list_item" v-for="(item, index) in orderList" :key="index"
					@click="$fn.jumpPage(`/pages/home/pages/identDetail?param=${item.number}`)">
					<view class="top">
						<view class="user">
							<image class="header" :src="vuex_imgUrl + item.avatar" mode=""></image>
							<view class="info">
								<view class="name">{{ item.nickname }}</view>
								<view class="time">{{ timeAgo(item.authenticationTime) }}</view>
							</view>
						</view>
						<image v-if="item.authenticationResult== 0" class="asTrue" src="/static/tabbar/asTrue.png"
							mode=""></image>
						<image v-else-if="item.authenticationResult== 1" class="asTrue" src="/static/tabbar/asFalse.png"
							mode=""></image>
						<view class="status" v-else-if="item.authenticationResult==3">待补图</view>
						<view class="status" v-else-if="item.authenticationResult==2">无法判断</view>
						<!-- 还差2个状态 -->
					</view>
					<image class="picture" v-if="item.itemImage" :src="vuex_imgUrl + item.itemImage" mode="">
					</image>
				</view>

			</view>
		</c-scroll-list>

	</view>
</template>

<script>
	export default {
		onLoad() {},
		onShow() {
			this.getOrderListCount();
			this.getBanner();
			// this.getOrderIdentified();
		},
		data() {
			return {
				api: this.$api.getOrderIdentified,
				count: null,
				from: {
					itemType: 1
				},
				keyword: '',
				bannerList: [],
				bannerList2: [],
				selectTab: 1,
				orderList: []
			}
		},


		methods: {
			// 获取数据列表
			load(res) {
				console.log(res, '列表数据');
				this.orderList = res.list
			},
			getOrderListCount() {
				this.$api.getOrderListCount().then(res => {
					console.log(res, "平台总鉴定数")
					this.count = res.data;
				})
			},
			timeAgo(authenticationTime) {
				const now = new Date();
				const authTime = new Date(authenticationTime);
				const secondsDiff = Math.floor((now - authTime) / 1000);
				const minutesDiff = Math.floor(secondsDiff / 60);
				const hoursDiff = Math.floor(minutesDiff / 60);
				const daysDiff = Math.floor(hoursDiff / 24);

				if (secondsDiff < 60) {
					return `${secondsDiff}秒前`;
				} else if (minutesDiff < 60) {
					return `${minutesDiff}分钟前`;
				} else if (hoursDiff < 24) {
					return `${hoursDiff}小时前`;
				} else {
					return `${daysDiff}天前`;
				}

			},
			getOrderIdentified() {
				this.$api.getOrderIdentified(this.from).then(res => {
					console.log(res, '订单列表');
					this.orderList = res.data.list
					this.orderList = this.orderList.map(v => {
						console.log(v.itemImage, '图片');
						if (v.itemImage) {
							v.itemImage = JSON.parse(v.itemImage)

						} else {
							v.itemImage = []
						}
						return v
					})
					console.log(this.orderList)
				});
			},
			// 切换
			changeTab(e) {
				this.selectTab = e
				if (e == 1) {
					this.from.itemType = 1
				} else if (e == 2) {
					this.from.itemType = 2
				} else {
					this.from.itemType = null
				}
				// this.getOrderIdentified();
				setTimeout(() => this.$refs.list.refresh(), 100)
			},
			getBanner() {
				this.$api.getBanner().then(res => {
					console.log(res, 'banner地址');
					this.bannerList = res.data.map(item => this.vuex_imgUrl + item.image);
					this.bannerList2 = res.data.map(item => item.id);
					console.log(this.bannerList2, 'bannerid');
				});
			},
			// 点击banner
			clickBanner(e) {
				// console.log('点击的banner', e);
				const id = this.bannerList2[e]
				// console.log(id)
				uni.navigateTo({
					url: `/pages/home/pages/bannerDetail?bannerId=${id}`
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.homeTopBg {
		width: 750rpx;
		height: 480rpx;
		position: absolute;
		top: 0;
		z-index: -1;
	}

	.head {
		padding: 136rpx 48rpx 0;
		box-sizing: border-box;
		height: 480rpx;

		.accumulate {
			font-size: 28rpx;
			color: #FFFFFF;
		}

		.accumulate_num {
			font-family: D-DIN-DIN, D-DIN-DIN;
			font-weight: bold;
			font-size: 80rpx;
			color: #FFFFFF;
			margin: 40rpx 0 48rpx;
		}

		.apply_btn {
			width: 640rpx;
			height: 80rpx;
			background: #01FFCC;
			border-radius: 48rpx;
			margin: 0 auto;
			font-weight: bold;
			font-size: 32rpx;
			color: #1A1A1A;
			line-height: 80rpx;
			text-align: center;
		}
	}

	.search {
		padding: 32rpx;
		box-sizing: border-box;
	}

	.divider {
		width: 750rpx;
		height: 2rpx;
		background: #D7D9D8;
		margin: 32rpx 0;
	}

	.status {
		width: 56rpx;
		font-weight: bold;
		font-size: 28rpx;
		color: #F53100;
		line-height: 36rpx;
	}

	.tabs {
		padding: 0 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;


		.tab {
			width: 232rpx;
			height: 80rpx;
			border-radius: 12rpx;
			border: 1rpx solid #4D4D4D;
			font-size: 28rpx;
			color: #666666;
			line-height: 80rpx;
			text-align: center;
		}

		.taball {
			width: 182rpx;
			height: 80rpx;
			border-radius: 12rpx;
			border: 1rpx solid #4D4D4D;
			font-size: 28rpx;
			color: #666666;
			display: flex;
			align-items: center;
			justify-content: center;
			gap: 16rpx;
		}

		.tab_a {
			background: #01FFCC;
			border: 3rpx solid #1A1A1A;
			font-weight: 800;
			font-size: 32rpx;
			color: #1A1A1A;
		}

	}

	.list {
		padding: 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		justify-content: space-between;

		.list_item {
			margin-bottom: 32rpx;

			.top {
				width: 330rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.user {
					display: flex;
					align-items: center;
					gap: 16rpx;

					.header {
						width: 80rpx;
						height: 80rpx;
						border-radius: 8rpx;
					}

					.info {
						display: flex;
						flex-direction: column;
						gap: 6rpx;
						justify-content: center;

						.name {
							font-size: 28rpx;
							color: #1A1A1A;
						}

						.time {
							font-weight: 400;
							font-size: 20rpx;
							color: #666666;
						}

					}

				}

				.asTrue {
					width: 72rpx;
					height: 72rpx;
					margin-right: 10rpx;
				}

			}

			.picture {
				width: 330rpx;
				height: 330rpx;
				margin-top: 16rpx;
			}

		}

	}
</style>